home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / DANG_SRC.LZH / EVENTS2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  5.6 KB  |  187 lines

  1. /*IMPORTANT!!!!!  second to last line of code has return(0) this
  2. disables ecounters!! set to return 1 to enable!!! */
  3. #include<globals2.h>
  4.  
  5. /* This module is really the heart of the program.
  6.     It checks for events after every turn. I.e. 
  7.     encounters, time, food, hp,sp.
  8.  
  9.     It will call many other modlues such as:
  10.  
  11.                          encounter...etc. */
  12.  
  13. char _clock_[] = "2 clock";       /*sound sample */
  14. char thunder[] = "2 thund";
  15. char crow[]    = "2 crow1";
  16.  
  17. int events()
  18.    {
  19. /* GLOBAL variable CURRENT_SKY holds the color of the current sky. */
  20. /* global CURRENT_CLOUD holds color of cloud if raining */    
  21.     int check;
  22.     static int semaphore =0;
  23.     static int raining = 0;
  24.     static int condition = 555;      /* variable, if roll a # greater than this, then encounter! */
  25.     static int c_twice=0;        /* set if roll > condition */
  26.  
  27.     /* Weather forecast */
  28.     mssg_count++;  /* inc the mssg count */
  29.     if (mssg_count == 5) {clear_it(); mssg_count=0;}
  30.     if ( weather == 1 && !semaphore) { semaphore=1;/*turn off for now */
  31.                           Dosound( wind_sound );
  32.                           condition= 522; /* probability of encounter is low */}
  33.     if (weather == 4  && !semaphore) {semaphore=1; /* set so we will not enter again, until new weather occurs */
  34.                         raining = 1;
  35.                         compute_rain_cloud();
  36.                      
  37.                         Setcolor(6,CURRENT_CLOUD);  /* grey sky */
  38.                         Dosound( rain_sound );
  39.                         condition = 380; /* encounter is high! */}
  40.     if (weather == 2 && !semaphore) { Dosound( quiet );}
  41.     if (weather == 3 && !semaphore) { Dosound( quiet );}
  42.     if (weather == 5 && !semaphore) { Dosound( quiet );}
  43.     if (weather == 0 && !semaphore) { Dosound( quiet );}
  44.  
  45.     CURRENT_SOUND = weather;          /* get value of current sound */
  46.  
  47.     check = pos_rnd(30000);
  48.     if( check > 29983)
  49.     {
  50.      check = pos_rnd(1000);
  51.      if(check > 50)
  52.        {
  53.         
  54.         Setcolor(6,change[count]);  /*chane sky back from rainy, gloomy*/
  55.          semaphore = 0;  /* reset so we can enter a sound routine*/
  56.          raining = 0;    /* reset so we can change sky */
  57.          check = pos_rnd(6);      
  58.           weather = check;  /* get the weather */
  59.                             /* 0 = Normal, 1= Windy, 2=Cool, 3=Hot, 4=Rainy, 5 = Cold!, 6 = Overcast*/
  60.        }
  61.     }
  62.     /*keep track of time */
  63.     time++;
  64.  
  65.     if( !raining )
  66.       Setcolor(6,change[count]);  /*change sky */
  67.  
  68.      /* check to see if your starving.. */
  69.      if(user.hunger_thurst_status[0] > 6) user.hp--;
  70.      if(user.hunger_thurst_status[1] > 6) user.hp--;
  71.  
  72.   
  73.     if(time >= HOUR_VALUE)
  74.      {
  75.       time = 0;
  76.       compute_time();  /* inc count if == 12 or 24 call invoketsr(clock) */
  77.       if (count == 12 || count == 24)
  78.        {
  79.  
  80.         v_gtext(handle,6,51,"A clock tolls in");
  81.         v_gtext(handle,6,59,"the distance......");
  82.         invoke_tsr( _clock_ );      /*play clock */
  83.         if(CURRENT_SOUND == 1) Dosound( wind_sound );
  84.         if(CURRENT_SOUND == 4) Dosound( rain_sound );
  85.          
  86.           /* reset all active spells!! */
  87.           for(check=0;check<5;check++)
  88.           user.current_spells_active[check] = 0;
  89.           
  90.           /* update hunger/thirst stats */
  91.           user.hunger_thurst_status[0]+=2; /*hunger */
  92.           user.hunger_thurst_status[1]+=2; /* thirst */
  93.         
  94.           /* if cursed... */
  95.           if( user.user_items[16] ) user.inte--;         
  96.        }/* end of if count == 12 or 24 */
  97.        
  98.   
  99.       if(raining){
  100.                   compute_rain_cloud();   
  101.                   Setcolor(6,CURRENT_CLOUD);  /* update rain cloud color */
  102.                  }
  103.       if(weather !=4)Setcolor(6,CURRENT_SKY);
  104.  
  105.           }/* end of time == hour value */
  106.     /* and food,hp,sp! */
  107.  
  108.  
  109.    /* if raining, play thunder every once and awhile */
  110.    if (raining)
  111.       {
  112.        if( (pos_rnd(1500)) > 1497)    
  113.        {   
  114.         invoke_tsr( thunder );      /*play  */
  115.          Dosound( rain_sound );     /* restore rain sound */
  116.        }
  117.       }
  118.    if((pos_rnd(1500)) > 1497) 
  119.      {
  120.        if((pos_rnd(1500)) > 1497) 
  121.        {
  122.         v_gtext(handle,6,11,"A crow cries in the");
  123.         v_gtext(handle,6,19,"distance...");
  124.         invoke_tsr( crow );      /*play */
  125.         if(CURRENT_SOUND == 1) Dosound( wind_sound );
  126.         if(CURRENT_SOUND == 4) Dosound( rain_sound );
  127.        }
  128.      }
  129.       
  130.       
  131.     
  132.        
  133.  
  134.    CURRENT_SKY = change[count];
  135.      /*check for encounter! */
  136.     check=pos_rnd(condition+10);   /*roll a 1d12....0-11*/
  137.     
  138.  if(char_alive ==0) game_over();      /* for mon_alive to be 0, ALL*/
  139.  
  140.  
  141.  
  142. /* CONDITION GETS LOWER W/NITE AND BAD WEATHER*/
  143.  
  144.  
  145.    check += user.lvl;  /* so easier to encounter monsters the 
  146.                           higher your level */
  147.     if(check>condition)    
  148.      {
  149.        if ( c_twice == 8 )
  150.         {
  151.            c_twice = 0;
  152.            return(1);
  153.          }
  154.     c_twice++;   /* set. next time thru if true the encounter */ 
  155.       } 
  156.    
  157.     return(0);
  158.  
  159.    }
  160.   
  161.  
  162.  
  163.  
  164.  
  165. /**/
  166. compute_time()
  167. {
  168. if(count > 24) count = 1;
  169.  
  170. count++;
  171.  
  172. }
  173. /***/
  174. compute_rain_cloud()
  175. {
  176.   
  177.   if(count > 0 && count < 5) CURRENT_CLOUD=0x111;
  178.   else if(count > 4 && count < 7) CURRENT_CLOUD=0x222;
  179.   else if(count > 6 && count < 10) CURRENT_CLOUD=0x333;
  180.   else if(count > 9 && count < 18) CURRENT_CLOUD=0x444;
  181.   else if(count > 17 && count < 20) CURRENT_CLOUD=0x333;
  182.   else if(count > 19 && count < 23) CURRENT_CLOUD=0x222;
  183.   else if(count > 22 && count < 25) CURRENT_CLOUD=0x111;
  184.  
  185.  
  186. }
  187.